<?php
namespace frontend\behaviors;

class ApiAuthBehaviors extends \common\behaviors\ApiAuthBehaviors
{
    const TOKEN_PARAM = 'token';
    /**
     * Authenticates the current user.
     *
     * @param \yii\web\User     $user
     * @param \yii\web\Request  $request
     * @param \yii\web\Response $response
     *
     * @return \yii\web\IdentityInterface the authenticated user identity. If authentication information is not
     *                                    provided, null will be returned.
     * @throws \yii\web\UnauthorizedHttpException if authentication information is provided but is invalid.
     */
    public function authenticate($user, $request, $response)
    {
        $token = $request->getHeaders()[self::TOKEN_PARAM];
        if (!$token) {
            return null;
        }
        return  $user->loginByAccessToken($token);
    }
}
